package roborally.Conditions;
import java.util.List;
import java.util.Set;

import roborally.*;

/**
 * A class of At-item-conditions for playing the roborally game, involving static final at-item.
 * 
 * @version  2.90
 * @author   Michiel Ruelens & Dieter Naten
 */
public class At_item extends Condition {

	private static final At_item ai = new At_item();
	
	/**
	 * Create a new At-item.
	 */
	private At_item(){
		this.setStringForm("At-item");
	}
	
	/**
	 * Get the at-item. Because it is not nessecary to make multiple objects of this class, the same object is always returned.
	 */
	public At_item getInstance(){
		return this.ai;
	}
	
	/**
	 * Check whether this robot is able to pick up a carryable or not.
	 * @pre		The robot must exist.
	 * @pre		The robot must be on a board.
	 */
	@Override
	public boolean validate(Placeable placeable) {
		assert(placeable!=null);
		assert(placeable.getBoard()!=null);
		boolean result = false;
		if(placeable instanceof Robot){
			Board board = placeable.getBoard();
			//The robot itself is definately at the given position so the set will never be empty or null.
			Set<Placeable> placeableSet = board.getAllObjectsByPosition(placeable.getX(), placeable.getY());
			for(Placeable p:placeableSet){
				if(p instanceof Carryable){
					result = true;
				}
			}
		}
		return result;
	}

}
